from collections import deque


def f(fishes):
    stack = deque()  # 小压大， 从右往左看
    ans = 0
    for i in range(len(fishes) - 1, -1, -1):
        cur_turn = 0
        while stack and fishes[i] >= stack[-1][0]:
            cur_turn = max(cur_turn + 1, stack.pop()[1])
        stack.append([fishes[i], cur_turn])
        ans = max(ans, cur_turn)
    return ans


n = int(input())
fishes = list(map(int, input().split()))
print(f(fishes))